package com.atguigu.gmall.payment.consumer;

import com.atguigu.gmall.payment.service.PaymentInfoService;
import com.atguigu.gmall.rabbit.constant.MqConst;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 接收支付相关的消息
 */
@Component
public class PaymentReceiver {


    @Autowired
    private PaymentInfoService paymentInfoService;

    @RabbitListener(queues = MqConst.QUEUE_PAYMENT_CLOSE)
    public void closePayment(Long orderId, Message message, Channel channel) throws Exception {
        System.out.println("取消支付");
        paymentInfoService.closePayment(orderId);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }
}
